home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15574 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.ucdavis.edu!quad!knight
  2. From: knight@quad.cs.ucdavis.edu (James Knight)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character  -  Making a better fgets?
  5. Followup-To: comp.lang.c,comp.unix.programmer
  6. Date: 19 Apr 1996 22:07:13 GMT
  7. Organization: University of California, Davis
  8. Message-ID: <4l92qh$ft7@mark.ucdavis.edu>
  9. References: <31616F63.481D@lava.weeg.uiowa.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl> <3169994D.665ACF69@cs.ucl.ac.uk> <4l6flq$rck@mark.ucdavis.edu> <4l8dmuINN6lf@keats.ugrad.cs.ubc.ca>
  10. NNTP-Posting-Host: quad.cs.ucdavis.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) wrote:
  14. : In article <4l6flq$rck@mark.ucdavis.edu>,
  15. : James Knight <knight@quad.cs.ucdavis.edu> wrote:
  16. : >                     4.5MB,              1MB,
  17. : >                   short lines         one line
  18. : >                   -----------         --------
  19. : >1) fgetc/fputc       23.00               5.32
  20. : >2) getc/putc         17.56               4.09
  21. : >3) fgets/fputs       17.80               N/A
  22. : >4) my_getline        17.52               3.96
  23. : >5) freadln           19.70               4.20
  24. : >6) reimplement       19.82               4.44
  25. : >7) optimize          18.22               4.22
  26. : >8) read/write         9.65               1.46
  27.  
  28. : >Now, this actually suprised the heck out of me, so I reran the test
  29. : >for 2, 3, 4 and 5 a number of times.  Even though I wrote my_getline,
  30. : >I never expected it to be as fast as the getc/putc version.  Could
  31.  
  32. : Told you so. :) I'm not a _total_ idiot, you know...
  33.  
  34. You were right about the getc/putc version versus the fgetc/fgetc
  35. version, but that isn't what suprised me.  What suprised me was that
  36. the my_getline version, with it's use of fgets and strlen, was 
  37. faster than the getc/putc version.  I wrote my_getline for simplicity,
  38. to make an easier to use fgets, not for speed (since I still don't
  39. have the same intuitive understanding for optimization that I do for
  40. programming).  So, the question I have is why did version 4 run
  41. faster than version 2?  From looking at the respective codes and with
  42. my understanding of getc/putc versus fgets/strlen, it shouldn't have.
  43.  
  44. Jim
  45.  
  46.